/**********************************************************

     文件名称: quier_sales.c

     项目功能: 查询所有收银员的销售记录 

     作者: 佳奇

     邮箱: 1374804492@qq.com 

     创建时间: Sat 27 Aug 2022 09:24:26 AM CST

**********************************************************/


#include <stdio.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include "sup_mgr.h"


struct tm* pt = NULL;

//	查询所有收银员的销售记录
//	遍历 输出 销售记录链表
void quier_sales(sales_list* demo)
{
	int cnt = 0;
	demo  = demo->next;

	system("clear");
	printf("\n********所有收银员销售记录如下********\n");

	while(demo != NULL)
	{
		pt = localtime(&demo->data->sell_time);

		printf("收银员姓名:%s   商品条码:%d   卖出时间:%d年%d月%d日 %d:%2d   商品总价:%d   备注:%s   \n", demo->data->name, demo->data->bar, pt->tm_year + 1900, pt->tm_mon + 1, pt->tm_mday, pt->tm_hour, pt->tm_min, demo->data->total, demo->data->note);

		printf("\n");

		demo = demo->next;
		cnt++;
	}

	printf("\n共有 %d 条销售记录\n", cnt);
	printf("\n查询完毕 按任意键返回上一级菜单:");
	getchar();
	c_buffer();
}


//	按收银员姓名统计该收银员的销售总额
void cas_total(sales_list* demo)
{
	int rmb = 0, index = 0;
	char name[31];

	sales_list* s1 = demo->next;
	demo = demo->next;

	system("clear");

	printf("\n********按收银员统计销售总额模式********\n");

	while(1)
	{
		printf("\n请输入您要查看的收银员姓名:");
		scanf("%30s", name);
		c_buffer();

		while(demo != NULL)
		{
			if(strcmp(demo->data->name, name) == 0)
			{
				rmb += demo->data->total;
				index = 1;
			}

			demo = demo->next;
		}

		if(index)
		{
			printf("\n%s 的销售总额为:%d \n", name, rmb);
			printf("********************\n");
			printf("\n是否继续进行此操作(y/n):");
			if(getchar() == 'y')
			{
				system("clear");
				rmb = 0;
				demo = s1;
				continue;
			}	
			else break;
		}
		else
		{
			printf("\n未查询到该收银员的任何销售信息!\n");
			printf("\n是否继续进行此操作(y/n):");
			if(getchar() == 'y')
			{
				system("clear");
				rmb = 0;
				demo = s1;
				continue;
			}	
			else break;
		}
	}
}

